#include <stdexcept>
#include <iostream>
#include <cstdlib>

template <class T>
class Array_impl
{
public:
    Array_impl():len(-1),array(NULL){};
    Array_impl(int);
    ~Array_impl();
private:
    int len;
    T* array;
};

template <class T>
Array_impl<T>::Array_impl(int length)
{
    //std::auto_ptr<T>    //??Howto??
    //My designed exception  //??Howto?? 
    try {
        if(length < 0) 
            throw std::invalid_argument("Array length argument error!");
        array= new T[length]; 
    }catch (const std::invalid_argument &e){
        std::cerr<<"Invalid argument for array length!"<<std::endl;
    }catch (const std::bad_alloc &e){
        std::cerr<<"Out of memory for Array_impl alloc!"<<std::endl;
    }
}

template <class T>
Array_impl<T>::~Array_impl()
{
    try {
    if(array!=NULL)
        delete []array;
    }catch (...) {
        std::cerr<<"Array [] delete error!"<<std::endl;
        abort();
    }
}
